package com.wwwarehouse.contract.program_operation;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by feng.gao on 2017/9/28.
 */

public class ArithMetic {
	/**
	 * 更改最小比例的算法
	 * @param meteList
	 * @param minValue
	 * @return
	 */
	public static List<Double> getPinRatio(List<Double> meteList, Double minValue) {
		Double TotalMax = 0d;
		Double smallDiffValue = 0d;

		for (int i = 0; i < meteList.size(); i++) {
			if (meteList.get(i) >= minValue) {
				TotalMax = TotalMax + meteList.get(i);
			}

		}

		for (int i = 0; i < meteList.size(); i++) {
			if (meteList.get(i) < minValue) {
				Double deff = minValue - meteList.get(i);
				smallDiffValue = smallDiffValue + deff ;
			}
		}
		for (int i = 0; i < meteList.size(); i++) {
			if (meteList.get(i) < minValue) {
				meteList.set(i, minValue);
			}
		}
		for (int i = 0; i < meteList.size(); i++) {
			if (meteList.get(i) > minValue) {
				meteList.set(i, ArithUtil.sub(meteList.get(i), ArithUtil.mul(meteList.get(i), ArithUtil.div(smallDiffValue, TotalMax))));

			}
		}

		return meteList;

	}
}
